<template>
  <div>
    <el-col>
      <el-row>
        <el-col :span="5" style="overflow: hidden;overflow-y: scroll" :style="m_style">
          <el-col v-for="item in mapList" :key="item.id" class="map-item">
            <el-link :underline="false" @click="getTask(item.id)">
              <span style="font-size: 18px;color: #409eff">
                {{ item.name }}
              </span>
              <span style="font-size: 16px;color: #767676">
                &nbsp;&nbsp;&nbsp;&nbsp;({{ item.total }})
              </span>
            </el-link>
          </el-col>

        </el-col>
        <el-col :span="19" style="overflow: hidden;overflow-y: scroll" :style="m_style">

          <el-col style="margin-top: 10px">
            <el-form-item label="任务查询">
              <el-input
                  v-model="searchStr"
                  placeholder="请输入"
                  style="width: 80%;"
                  v-on:keyup.enter="searchT"
              >
                <template #prepend>
                  <el-button :icon="Search"/>
                </template>
              </el-input>
              <el-button @click="searchT">查询</el-button>

            </el-form-item>
          </el-col>

          <el-col
              style="margin-top: 15px;display: flex;flex-direction: column;justify-content: center;flex-wrap: nowrap;align-items: center">
            <el-tooltip placement="left" v-for="item in taskList" :key="item.id">
              <template #content>
                <template v-for="r in item.reward" :key="r.type">
                  <p v-if="r.type==='train'">
                    修为: {{ r.count }}
                  </p>
                  <p v-if="r.type==='exp'">
                    阅历: {{ r.count }}
                  </p>
                  <p v-if="r.type==='tongFund'">
                    帮会资金: {{ r.count }}
                  </p>
                  <p v-if="r.type==='money'">
                    <span v-if="r.count > 10000">
                       金钱:
                      {{ Math.floor(r.count / 10000) }}金
                      <span>
                        {{ Math.floor((r.count - (Math.floor(r.count / 10000) * 10000)) / 100) }}银
                      </span>

                      <span>
                        {{ (r.count / 100) % 10 }}{{ r.count % 10 }}铜
                      </span>
                    </span>

                    <span v-if="r.count > 100 && r.count < 10000">
                       金钱:
                      <span>
                        {{ Math.floor(r.count / 100) }}银
                      </span>
                      <span>
                        {{ (r.count / 100) % 10 }}{{ r.count % 10 }}铜
                      </span>
                    </span>

                    <span v-if="r.count < 100">
                       金钱:
                      <span>
                        {{ r.count }}铜
                      </span>
                    </span>
                    <!--                    <span v-if="r.count > 100 && r.count/10000 < 1">{{ Math.floor(r.count / 100) }}银</span>-->
                    <!--                    <span v-if="r.count/10000 > 1">{{ (r.count - Math.floor(r.count / 10000)) / 100 }}银</span>-->
                  </p>
                </template>

              </template>
              <el-card style="margin-top: 15px;width: 95%;min-height: 80px"
                       shadow="hover">
                <el-col style="display: flex;flex-wrap: nowrap;justify-content: flex-start;align-items: center">
                  <el-col :span="4" style="line-height: 40px">
                    {{ item.map }}
                  </el-col>
                  <el-col :span="6" style="text-align: center">
                    <span style="font-size: 18px">{{ item.name }}</span><br/>
                    <el-tooltip :content="'该任务只能由'+item.schoolName+'门派完成'">
                      <el-image v-if="item.schoolName!==null"
                                :src="'https://img.jx3box.com//image/school/'+item.schoolName+'.png'"
                                style="height: 30px;width: 30px;display: inline-block"></el-image>
                    </el-tooltip>

                    <span style="font-size: 16px;color: #d2d2d2">(ID:{{ item.id }})</span>
                  </el-col>
                  <el-col :span="4" style="text-align: center">
                    <span>可接等级:{{ item.level }}</span>
                  </el-col>

                  <el-col :span="10">
                    <span style="overflow-y: hidden;font-size: 15px;color: #686868">{{ item.target }}</span>
                  </el-col>
                </el-col>
                <el-col>
                  <m>
                    <details close>
                      <summary></summary>
                      <div class="tab-content">
                        <template v-for="r in item.reward" :key="r">
                          <span v-if="r.type ==='item_group'">{{r.items}}</span>
                        </template>
                      </div>
                    </details>
                  </m>

                </el-col>
              </el-card>
            </el-tooltip>
            <el-pagination background layout="prev, pager, next" :total="total" v-model:current-page="pageCount"
                           @current-change="pageChange" style="margin-top: 15px"/>
          </el-col>

        </el-col>
      </el-row>

    </el-col>
  </div>
</template>

<script>
import {j3api} from "@/axios/j3http";
import {Search} from '@element-plus/icons-vue'

export default {
  name: "TaskPage",
  data() {
    return {
      mapList: [],
      m_style: {
        height: (document.documentElement.clientHeight - 40) + 'px',
        paddingBottom: '30px'
      },
      pageCount: 1,
      total: 0,
      thisId: 0,
      taskList: [],
      Search,
      searchStr: '',
      searchType: 'id'
    }
  },
  methods: {
    getTask(id) {
      if (this.searchType === 'search'){
        this.pageCount = 1
      }
      this.searchType = 'id'
      this.thisId = id
      j3api.getTaskList(id, this.pageCount).then(res => {
        this.total = res.total
        this.taskList = res.list.byKeyword
        console.log(this.taskList);
      })
    },
    pageChange() {
      if (this.searchType === 'id') {
        this.getTask(this.thisId)
      }

      if (this.searchType === 'search') {
        this.searchT()
      }

    },
    searchT() {
      if (this.searchType === 'id'){
        this.pageCount = 1
      }
      this.searchType = 'search'
      j3api.searchTaskList(this.searchStr, this.pageCount).then(res => {
        console.log(res);
        this.total = res.total
        this.taskList = res.list.byKeyword
      })
    }
  },
  mounted() {
    j3api.getMapList().then(res => {
      this.mapList = res
    })
    this.getTask(1)
  }
}
</script>

<style scoped>
.el-popper.is-customized {
  padding: 5px;
  background: linear-gradient(90deg, rgb(159, 229, 151), rgb(204, 229, 129));
}

.el-popper.is-customized .el-popper__arrow::before {
  background: linear-gradient(45deg, #b2e68d, #bce689);
  right: 0;
}
</style>
